/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2016 All Rights Reserved.
 */
package tbdp.tas.hbase;

import tbdp.tas.hbase.impl.HbaseConnectorImpl;

import java.util.concurrent.ConcurrentHashMap;


/**
 * 复用缓存hbase 链接
 *
 * @author xbkaishui
 * @version $Id: HBaseConnectionFactory.java, v 0.1 2016-5-25 下午9:06:41 xbkaishui Exp $
 */
public class HBaseConnectionFactory {

    private static HBaseConnectionFactory instance = new HBaseConnectionFactory();
    private static ConcurrentHashMap<HBaseConnection, HbaseConnector> holder = new ConcurrentHashMap<HBaseConnection, HbaseConnector>();

    private Object lock = new Object();

    private HBaseConnectionFactory() {
    }

    public static HBaseConnectionFactory instance() {
        return instance;
    }

    public synchronized  HbaseConnector  getHbaseConnector(HBaseConnection conn) {
        HbaseConnector connector = holder.get(conn);
        if (connector == null) {
                if (holder.get(conn) == null) {
                    connector = new HbaseConnectorImpl(conn);
                    connector.init();
                    holder.putIfAbsent(conn, connector);
                }
        }
        return connector;
    }

}
